Int_t EnableGlobalParFile(TString proof,TString parfilename="",TString rootver="",TString opt="",TString tmpPath="/tmp/.proof") {

  
  gSystem->Exec(Form("rm -Rf %s",tmpPath.Data()));
  gEnv->SetValue("Proof.Sandbox",tmpPath.Data());
  gEnv->SetValue("XSec.GSI.DelegProxy","2");
	
  TProof::Mgr(proof.Data())->SetROOTVersion("VO_ALICE@ROOT::current");
  
  if (!rootver.IsNull()) {
    TProof::Mgr(proof.Data())->SetROOTVersion(rootver.Data());
  }
  
  TProof *p = TProof::Open(proof.Data(),"workers=1x");
  
  if (!p) {
    Error("",Form("Could not connect to %s !!!",proof.Data()));
    return 1;
  }

  // remove .par from name
  parfilename.ReplaceAll(".par","");
  Info("EnableGlobalParFile.C",Form("parfile %s | opt %s",parfilename.Data(),opt.Data()));
  if (!opt.IsNull()) {
    opt.ToUpper();
    if (!opt.CompareTo("CLEARALL")) {
      p->ClearPackages();
      return 0;
    } else if (!opt.CompareTo("CLEARPACKAGE")){
      p->ClearPackage(parfilename.Data());
      return 0;
    }    
  }

  Int_t retVal;
  retVal = p->UploadPackage(parfilename.Data());
  if (retVal) {
    Error("",Form("Error in gProof->UploadPackage(\"%s\") !!!",parfilename.Data()));
    return 2;
  
  }
  
  retVal = p->EnablePackage(parfilename.Data());
  if (retVal) {
    Error("",Form("Error in gProof->EnablePackage(\"%s\") !!!",parfilename.Data()));
    return 3;
  
  }
  
  return 0;
}
